<template>
  <div>
    <Btn @getX="(val) => (num = val)" />
    <hr />
    <button>父组件按钮{{ num }}</button>
    <hr />
    <!-- 在组件上使用 ref 可以拿到子组件实例 -->
    <Btn2 ref="btn2" />
    <hr />
    <button @click="$refs.btn2.add">父组件按钮{{ num }}</button>
  </div>
</template>
<script>
import Btn from "./components/Btn.vue";
import Btn2 from "./components/Btn2.vue";

export default {
  data() {
    return {
      num: 0,
    };
  },
  components: {
    Btn,
    Btn2,
  },
};
</script>
